package com.techsoul.module.accounting.controller;

import com.techsoul.common.core.pojo.Result;
import com.techsoul.common.core.pojo.vo.UserVo;
import com.techsoul.common.core.util.ServletUtils;
import com.techsoul.common.log.annotation.Log;
import com.techsoul.common.log.enums.OperationTypeEnum;
import com.techsoul.module.accounting.pojo.param.AccAccountingApHisSaveParam;
import com.techsoul.module.accounting.pojo.param.AccAccountingApHisSearchParam;
import com.techsoul.module.accounting.pojo.param.AccountingApSaveParam;
import com.techsoul.module.accounting.pojo.param.AccountingApSearchParam;
import com.techsoul.module.accounting.pojo.vo.AccAccountingApHisVo;
import com.techsoul.module.accounting.pojo.vo.AccountingApVo;
import com.techsoul.module.accounting.service.IAccAccountingApHisService;
import com.techsoul.module.order.pojo.vo.SalesOrderItemVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 财务应付 Controller
 *
 * @author liuen
 * @date 2021-07-31
 */
@Api(tags = "财务应付")
@RestController
@RequestMapping("/accountingApHis/accAccountingApHis")
public class AccAccountingApHisController {

    @Autowired
    private Result result;
    
    @Autowired
    private IAccAccountingApHisService service;

    @ApiOperation("新增")
    @Log(title = "财务应付", operationType = OperationTypeEnum.INSERT)
    @PreAuthorize("hasAnyAuthority('accountingApHis:accAccountingApHis:insert')")
    @PostMapping
    public Result insert(@Valid @RequestBody AccAccountingApHisSaveParam params) {
        return result.success(this.service.insert(params));
    }

    @ApiOperation("批量删除（多个用逗号隔开）")
    @Log(title = "财务应付", operationType = OperationTypeEnum.DELETE)
    @PreAuthorize("hasAnyAuthority('accountingApHis:accAccountingApHis:delete')")
    @DeleteMapping("/{ids}")
    public Result batchDelete(@PathVariable String[] ids) {
        return result.success(this.service.batchDelete(Arrays.asList(ids)));
    }

    @ApiOperation("修改")
    @Log(title = "财务应付", operationType = OperationTypeEnum.UPDATE)
    @PreAuthorize("hasAnyAuthority('accountingApHis:accAccountingApHis:update')")
    @PutMapping
    public Result update(@Valid @RequestBody AccAccountingApHisSaveParam params) {
        return result.success(this.service.update(params));
    }

    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('accountingApHis:accAccountingApHis:search')")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {
        return result.success(this.service.findById(id));
    }

    @ApiOperation("列表")
    @PreAuthorize("hasAnyAuthority('accountingApHis:accAccountingApHis:search')")
    @PostMapping("/search")
    public Result findAll(@RequestBody AccAccountingApHisSearchParam params) {
        return result.success(this.service.findAll(params));
    }

    @ApiOperation("列表-分页")
    @PreAuthorize("hasAnyAuthority('accountingApHis:accAccountingApHis:search')")
    @PostMapping("/search/{current}/{pageSize}")
    public Result findAll(@RequestBody AccAccountingApHisSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.findAll(params, current, pageSize));
    }

    @ApiOperation("供应商汇总列表-分页")
    @PreAuthorize("hasAnyAuthority('accounting:accountingAp:search')")
    @PostMapping("/supplierSumPage/{current}/{pageSize}")
    public Result supplierSumPage(@RequestBody AccountingApSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.supplierSumPage(params, current, pageSize));
    }

    @ApiOperation("供应商-查询结算明细")
    @PreAuthorize("hasAnyAuthority('accountingApHis:accAccountingApHis:search')")
    @PostMapping("/suppierViewAccount")
    public Result suppierViewAccount(@RequestBody Map map){
        String supplierNo = (String) map.get("supplierNo");
        String dateFrom = (String) map.get("dateFrom");
        String dateTo = (String) map.get("dateTo");
        List<AccAccountingApHisVo> retresult = this.service.suppierViewAccount(supplierNo,dateFrom,dateTo);

        return result.success(retresult);
    }





    @ApiOperation("品牌排行列表-分页")
    @PreAuthorize("hasAnyAuthority('accountingApHis:accAccountingApHis:search')")
    @PostMapping("/brandRateView/{current}/{pageSize}")
    public Result brandRateView(@RequestBody AccountingApSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.brandRateView(params, current, pageSize));
    }
    @ApiOperation("供应商排行列表-分页")
    @PreAuthorize("hasAnyAuthority('accountingApHis:accAccountingApHis:search')")
    @PostMapping("/supplierRateView/{current}/{pageSize}")
    public Result supplierRateView(@RequestBody AccountingApSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.supplierRateView(params, current, pageSize));
    }


}
